﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreHelper.Validation.Validators;

namespace CoreHelper.Validation
{
    public class ValidationItem
    {
        public string Name { get; set; }
        public object Value { get; set; }
        public List<BaseValidatorAttribute> Validations { get; internal set; }

        public ValidationItem()
        {
            Validations = new List<BaseValidatorAttribute>();
        }
        public ValidationItem(string name, object value) : this()
        {
            Name = name;
            Value = value;
        }
        public void LoadRules(Dictionary<string, RuleItem> ruleDict)
        {
            foreach (var kv in ruleDict)
            {
                if (!kv.Value.NotServerSide)
                {
                    Validations.Add(ValidationUtils.NewValidation(kv.Key, kv.Value));
                }
            }
        }
        public void AddRule(string name, string message, params object[] args)
        {
            Validations.Add(ValidationUtils.NewValidation(name, new RuleItem { Message = message, Params = args }));
        }
    }
}
